-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ec2): restrictDefaultSecurityGroup fails when default rules are not present #27039
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Exemption Request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the linked issue was written, it seemed like this bug was an issue caused by changes in the CDK, but it looks like that's not actually the case? The handler always assumed these default rules were present whether using sdk v2 or v3 right?
An integ test would be ideal for this but I'm not actually sure how we would accomplish it. Will add the exception.
try { | ||
await ec2.revokeSecurityGroupEgress(egressRuleParams(groupId)); | ||
} catch (e: any) { | ||
if (!(e instanceof Error) || (e instanceof Error && e.name !== 'InvalidPermission.NotFound')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just rolled back using typed exceptions in sdk v3 because there are some known issues with it. We should just use e.name
so we are in line with all our other custom resource code.
We should just be able to consolidate like so?
try {
await ec2.revokeSecurityGroupEgress(egressRuleParams(groupId));
await ec2.revokeSecurityGroupIngress(ingressRuleParams(groupId, account));
} catch (e: any) {
if (e.name === 'InvalidPermission.NotFound') {
return;
}
throw e;
}
Most typed exceptions in sdkV3 have a type for each different error.name
value with that field hardcoded in. However Ec2 just has ServiceException
with a bunch of different "error codes" which are also used as the error.name
field. I just ran the commands against a non-existing security group to ensure that these name fields are as expected since we can't verify them in the sdk code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your explanation. I removed error type checks.
Just found the error code InvalidPermission.NotFound
is listed in this doc.
We should just be able to consolidate like so?
I think these two API calls should be put into separate try-catch blocks, because even if the default egress rule is not found, we still want to execute revokeSecurityGroupIngress
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh yes, makes sense.
|
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one snapshot needs to be updated in framework-integ. Are you able to run the integration test?
@MrArnoldPalmer
When I try to update the snapshot,
it requests certificate using |
ahhh you know what, let me run this for you then. I forgot this was required here. |
@MrArnoldPalmer |
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was going to reapprove after merging in main but apparently I included some extra stuff that got generated during build. All this should be in main already or excluded. Sorry I'll clean this up tomorrow.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
When using restrictDefaultSecurityGroup to remove default security group rules, an error is thrown and the deploy rolls back if the default rules are not found.
This error usually happens when developers previously removed default rules manually or by other means, and then want to switch to using
restrictDefaultSecurityGroup
. They have to re-add default rules and deploy again to cope with the error.This PR fixes the custom resource to ignore the error when default rules are not found.
Closes #26390
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license